package com.cn.order.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cn.api.ali.BussOpenService;
import com.cn.api.ali.HelloOpenService;
import com.cn.api.ali.SkuOpenService;
import com.cn.buss.LzlCompany;
import com.cn.dataSource.Constants;
import com.cn.dataSource.DynamicDataSourceContxtHolder;
import com.cn.sku.SkuGood;
import com.cn.utils.Constant;
import com.cn.utils.PageUtils;
import org.apache.dubbo.common.utils.Page;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/ceshi1")
public class HelloController {

    @DubboReference(version = "1.0.0", check = false)
    private HelloOpenService helloOpenService;

    @DubboReference(version = "1.0.0", check = false)
    private BussOpenService bussOpenService;

    @DubboReference(version = "1.0.0", check = false)
    private SkuOpenService skuOpenService;

    @GetMapping("/list")
    public String ceshiHello2(){
        System.out.println("jcnaknc");
        return helloOpenService.ceshi("沙雕年好啊");
    }




    @GetMapping("/list3")
    public String ceshiHello3(String code,String categoryId){
        LzlCompany company = bussOpenService.getCompany(code);
        List<SkuGood> skuGoodList = skuOpenService.getSkuGoodList(company, categoryId);
        for (SkuGood skuGood : skuGoodList) {
            System.out.println("商家名称"+skuGood.getFromMerchant()+"    商品名称"+skuGood.getGoodName());
        }
        return "成功";
    }
    @GetMapping("/list4")
    public String ceshiHello4(String categoryId){
        for (String dataType : Constants.DS_NAME_LIST) {
            DynamicDataSourceContxtHolder.setDataSourceType(dataType);
            List<SkuGood> skuGoodList = skuOpenService.getSkuGoodList(null, categoryId);
            for (SkuGood skuGood : skuGoodList) {
                System.out.println("商家名称"+skuGood.getFromMerchant()+"    商品名称"+skuGood.getGoodName());
            }
        }
        return "成功";
    }

    @PostMapping(value = "/reception")
    @ResponseBody
    public void multipart(MultipartFile file){

        //MultipartFile file = baseFileVo.getFile();

        //String name1 = file.getName();
        System.out.println(file.getName());
        //System.out.println(name1);
        //选择用缓冲区来实现这个转换即使用java 创建的临时文件 使用 MultipartFile.transferto()方法 。
    /*File file = null;
    try {
        String name = multipartFile.getName();
        System.out.println(name);
        String originalFilename = multipartFile.getOriginalFilename();
        String[] filename = originalFilename.split("\\.");
        file=File.createTempFile(filename[0], filename[1]);    //注意下面的 特别注意！！！
        multipartFile.transferTo(file);
        file.deleteOnExit();
    } catch (IOException e) {
        e.printStackTrace();
    }

     */
    }
}
